#define _CRT_SECURE_NO_WARNINGS 1
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>

 typedef struct ListNode {
      int val;
     struct Node *next;
 }ListNode;
 

 struct ListNode* detectCycle(struct ListNode* head) {
     struct ListNode* slow = head;
     struct ListNode* fast = head;
     int flag = 0;
     if (head == NULL)
         return NULL;
     while ((fast->next) && ((fast->next)->next))
     {
         fast = fast->next->next;
         slow = slow->next;
         if (slow == fast)
         {
             flag = 1;
             break;
         }
     }
     if (flag == 1)
     {
         while (head != slow)
         {
             head = head->next;
             slow = slow->next;
         }
         return head;
     }
     else
     {
         return NULL;
     }
 }
int main()
{
    return 0;
}